<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>排行榜</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/formSelects/formSelects-v4.css"/>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">

                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">所属机构:</label>
                        <!--<div class="layui-input-inline mr0">
                            <input id="orgId" class="layui-input" type="text" placeholder="请选择所属机构"/>
                        </div>-->
                        <div class="layui-input-inline">
                            <select name="organizationId" id="organizationId"  lay-verType="tips"
                                    lay-filter="organization">
                                <option value="">全部</option>
                                <% for(organizations in organizationsList) { %>
                                <option value="${organizations.id}">${organizations.organizationName}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">所属校区:</label>
                        <div class="layui-input-inline">
                            <select name="schoolId" id="schoolId" lay-verType="tips" lay-filter="school">
                                <option value="">全部</option>
                                <% for(school in schoolList) { %>
                                <option value="${school.id}">${school.schoolName}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">所属班级:</label>

                        <div class="layui-input-inline">
                            <select name="classId" id="classId">
                                <option value="">全部</option>
                                <% for(classs in classsList) { %>
                                <option value="${classs.id}">${classs.className}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">关键词:</label>
                        <div class="layui-input-inline mr0">
                            <input id="keyWords" class="layui-input" type="text" placeholder="姓名/手机号"/>
                        </div>
                    </div>
                </div>

                <div class="layui-inline" style="margin-top: 20px;margin-left: 10px">
                    <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>查询</button>
                    <button id="btnReset" class="layui-btn icon-btn"><i class="layui-icon">&#xe669;</i>重置</button>
                </div>


                <div class="layui-form-item" style="margin-top: 10px">
                    <table class="layui-table" id="rankTable" lay-filter="rankTable" style="margin-top: 30px"></table>
                </div>

            </div>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="dictTableBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update">编辑</a>
</script>

<!-- 编辑 表单弹窗 -->
<script type="text/html" id="dictEditLayer">
    <form id="dictForm" lay-filter="dictForm" class="layui-form model-form dictForm"
          style="margin-left: 70px;height: 500px">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>所属机构:</label>
            <input name="dictName" placeholder="请输入" type="text" class="layui-input" lay-verType="tips"
                   autocomplete="off" lay-verify="required" style="width: 300px" />
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>所属校区:</label>
            <input name="dictName" placeholder="请输入" type="text" class="layui-input" lay-verType="tips"
                   autocomplete="off" lay-verify="required" style="width: 300px" />
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>所属班级:</label>
            <input name="dictName" placeholder="请输入" type="text" class="layui-input" lay-verType="tips"
                   autocomplete="off" lay-verify="required" style="width: 300px" />
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>关键词:</label>
            <input name="remark" placeholder="请输入" type="text" class="layui-input" lay-verType="tips"
                   autocomplete="off" lay-verify="required" style="width: 300px" />
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
            <button class="layui-btn" lay-filter="dictFormSubmit" lay-submit>保存</button>
        </div>

    </form>
</script>

<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>

<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate', 'upload', 'jquery', 'formSelects' ,'excel'],function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var formSelects = layui.formSelects;


        var insTb = table.render({
            elem: '#rankTable',
            url: 'rankList',
            page: true,
            cellMinWidth: 100,
            text: {none: '暂无数据'},
            cols: [[
                {type: 'checkbox'},
                {field: 'id', title: 'id' , width:50,hide: true},
                {field: 'rank', title: '排名',width:60,},
                {field: 'childName', title: '学员姓名' , width:200},
                {field: 'organizationName', title: '所属机构' , width:200},
                {field: 'schoolName', title: '所属校区' , width:200},
                {field: 'className', title: '所属班级' , width:200},
                {field: 'telNo', title: '手机号' , width:200},
                {field: 'rattanNum', title: '实时豆藤量'},
                {field: 'peaseNum', title: '实时金豆量' },
                {field: 'sumPeaseNum', title: '金豆累积量'},
                {field: 'rankName', title: '段位'}
            ]]
        });


        //var where = () =>( { keyWords: keyWords.value});
        //搜索
        $('#btnSearch').click(function () {
            var organizationId = $('#organizationId').val();
            var schoolId = $('#schoolId').val();
            var classId = $('#classId').val();
            var keyWords = $('#keyWords').val();
            console.log(keyWords);
            //insTb.reload({where: where() });
            insTb.reload({
                where: {
                    organizationId: organizationId,
                    schoolId: schoolId,
                    classId: classId,
                    keyWords: keyWords
                }
            });
        });

        // 重置
        $('#btnReset').click(function () {
            $("#classId").val("");
            $("#schoolId").val("");
            $("#organizationId").val("");
            $("#keyWords").val("");
            window.location.reload();
        });

        // 工具条点击事件
        table.on('tool(rankTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            switch (obj.event) {
                // 充值
                case 'update':
                    editDict(data);
                    break;
            }
        });

        //选择机构后筛选所负责的校区
        form.on('select(organization)', function (data) {
            changeSchool();
        });

        form.on('select(school)', function (data) {
            changeClasss();
        });

        function changeSchool() {
            $("#schoolId").empty();
            $("#classId").empty();
            form.render("select");//重新渲染 固定写法
            var organizationId=$("#organizationId").val();
            if(organizationId!=null && organizationId!=""){
                $.ajax({
                    url: '/admin/school/getListByOrganizationId?organizationId='+ organizationId,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#schoolId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $('#classId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $.each(data, function (index, item) {
                            $('#schoolId').append(new Option(item.schoolName, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                    }
                });
            }
        }

        function changeClasss() {
            $("#classId").empty();
            form.render("select");//重新渲染 固定写法
            var schoolId=$("#schoolId").val();
            if(schoolId!=null && schoolId!=""){
                $.ajax({
                    url: '/classs/getListBySchoolId?schoolId='+ schoolId,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#classId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $.each(data, function (index, item) {
                            $('#classId').append(new Option(item.className, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                    }
                });
            }
        }


    })

</script>

</body>
</html>